package com.balance.anole.client.retail.provider;

import java.text.DecimalFormat;
import java.text.FieldPosition;

import org.eclipse.jface.viewers.ITableColorProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;

import com.balance.anole.business.to.ProductPriceTO;
import com.balance.anole.client.retail.vo.RetailVO;
import com.balance.anole.common.to.CodeLookTO;
import com.balance.anole.utils.Constants;

public class RetailLabelProvider extends LabelProvider implements ITableLabelProvider , ITableColorProvider{
	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		return null;
	}

	@Override
	public String getColumnText(Object element, int columnIndex) {
		RetailVO retailVO = (RetailVO)element;
		switch(columnIndex){
			case 0:
				return retailVO.getPdtItem().getSn();
			case 1:
				return retailVO.getPdtItem().getProductTO().getPdtDesc();
			case 2:
				return retailVO.getPdtItem().getColorTO().getColorDesc();
			case 3:
				return retailVO.getPdtItem().getSizeTO().getSizeDesc();
			case 4:
				ProductPriceTO ppt = retailVO.getPdtItem().getProductTO().getPriceByType(new CodeLookTO(Constants.CODE_TYPE_PRODUCT_PRICE_TYPE, "S"));
				return ppt == null ? "" : ppt.getPrice() + "";
			case 5:
				return retailVO.getPdtItem().getProductTO().getDiscRate() + "";
			case 6:
				return retailVO.getNumOfPdtItem()+"";
			case 7:
				DecimalFormat df = new DecimalFormat("#0.00");
				return df.format(retailVO.getAmountAfterDiscount(), new StringBuffer(),new FieldPosition(0)).toString();
			default :
				return "unknown " + columnIndex;
		}
	}

	public Color getForeground(Object element, int columnIndex) {
		RetailVO retailVO = (RetailVO)element;
		if(retailVO.getNumOfPdtItem().intValue() < 0 ){
			return new Color(null, 255,0,0);
		}else{
			return new Color(null, 0,0,0);
		}
	}

	@Override
	public Color getBackground(Object element, int columnIndex) {
		return null;
	}
}
